package com.yjzx.util.binlog.core.entiry.recordIndex;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

/**
 * @author yjzx
 * @date 2024/11/18
 * @description BinaryLogClientIndex
 */
@Getter
@Setter
@EqualsAndHashCode
public abstract class BinaryLogClientIndex {
    String binFileName;
    long position;

    public BinaryLogClientIndex() {
    }

    public BinaryLogClientIndex(String binFileName, long position) {
        this.binFileName = binFileName;
        this.position = position;
    }

    /**
     * 获取顺序
     * @return
     */
    public abstract int getOrder();

    /**
     * 输入参数校验
     * @return
     */
    public abstract boolean valid();

    /**
     * 是否允许读取
     * @return
     */
    public abstract boolean isRead();

    /**
     * 是否允许写入
     * @return
     */
    public abstract boolean isWrite();

    /**
     * 写入binlog
     * @param binlogIndex
     */
    public void writeBinlogIndex(String binlogIndex){

    }

    /**
     * 无配置，默认配置
     * @return
     */
    public static BinaryLogClientIndex empty(){
        return new BinaryLogClientIndex() {
            @Override
            public int getOrder() {
                return Integer.MIN_VALUE;
            }

            @Override
            public boolean valid() {
                return true;
            }

            @Override
            public boolean isRead() {
                return true;
            }

            @Override
            public boolean isWrite() {
                return true;
            }

            @Override
            public void writeBinlogIndex(String binlogIndex) {

            }
        };
    }
}
